home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / t3_1 / sources.lha / sources / sys / combinators.t < prev    next >
Text File  |  1988-02-05  |  2KB  |  58 lines

  1. (herald combinators 
  2.   (env tsys))
  3.  
  4. ;;; Logical Connectives
  5.  
  6. ;;; These should be rewritten later to offer some sense of efficiency. 
  7. ;;; What we have here is extremely elegant if a bit silly. Will work for
  8. ;;; the time being... 
  9. ;;;
  10. ;;; Perhaps set operations could be regular operations, with these 
  11. ;;;  definitions as default handlers... however this loses because, like
  12. ;;;  arithmetic, they want to be unbiased with respect to particular args...
  13. ;;;  sigh. Can win with negation anyway, since it is unary...
  14.  
  15. ;;; Note elegance of things like (DISJOIN (.IN 0 10) (.IN 20 30)).
  16.  
  17. (DEFINE (DISJOIN . FNS)
  18.   (LAMBDA ARGLIST (ANY?   (LAMBDA (FN) (APPLY FN ARGLIST)) FNS)))
  19.  
  20. (DEFINE (CONJOIN . FNS)
  21.   (LAMBDA ARGLIST (EVERY? (LAMBDA (FN) (APPLY FN ARGLIST)) FNS)))
  22.  
  23. (DEFINE (COMPLEMENT FN)
  24.   (LAMBDA ARGLIST (NOT (APPLY FN ARGLIST))))
  25.  
  26. ;;; As an operation, the above would look like:
  27. ;;;
  28. ;;; (DEFINE-OPERATION (COMPLEMENT FN)
  29. ;;;   (LAMBDA ARGLIST (NOT (APPLY FN ARGLIST))))
  30. ;;;
  31.  
  32. ;;; (COMPOSE f g ...)
  33. ;;;
  34. ;;; Composes procedures of 1 argument.  What would it mean to compose procedures
  35. ;;;  of more than 1 argument?  Returns a procedure which works like the 
  36. ;;;  composition of these.  Note, 
  37. ;;;
  38. ;;;     ((COMPOSE x1 x2 ... xN) y)  <=>  (x1 (x2 ... (xN y) ...))
  39. ;;;
  40. ;;;  so, for example,
  41. ;;;
  42. ;;;             CADR   is like  (COMPOSE CAR CDR)
  43. ;;;             CDDAR  is like  (COMPOSE CDR CDR CAR)
  44. ;;;
  45. ;;; Compiler should know about COMPOSE.  We wouldn't want ((COMPOSE ...) ...)
  46. ;;; to cons a closure.
  47. ;;;
  48. ;;; Last may a procedure of more than one argument.
  49.  
  50. (DEFINE (COMPOSE . PROCS)
  51.   (COND ((NULL? PROCS) PROJ0)
  52.         ((NULL? (CDR PROCS)) (CAR PROCS))
  53.         (ELSE (LET ((PRELUDE (APPLY COMPOSE (CDR PROCS)))
  54.                     (FINALLY (CAR PROCS)))
  55.                 (LAMBDA ARGS
  56.                   (FINALLY (APPLY PRELUDE ARGS)))))))
  57.  
  58.